package com.mike.demo.controller;

import com.mike.demo.po.User;
import com.mike.demo.service.DemoService;
import com.mike.mvcframework.annotations.MyAutowired;
import com.mike.mvcframework.annotations.MyController;
import com.mike.mvcframework.annotations.MyRequestMapping;
import com.mike.mvcframework.annotations.MySecurity;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description
 * @Date 2021/7/23 6:57
 * @Created by mike
 */
@MyController
@MyRequestMapping("/demo")
public class DemoController {

    @MyAutowired
    private DemoService demoService;

    @MyRequestMapping("/getDemo")
    public User getDemo(HttpServletRequest request, HttpServletResponse response,String name){
        User user = demoService.getUserByName(name);
        try {
            response.getWriter().write(name);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(user);
        return user;
    }
    @MyRequestMapping("/zhangsan")
    @MySecurity({"zhangsan"})
    public void zhangsan(HttpServletRequest request, HttpServletResponse response){
        try {
            response.getWriter().write(request.getParameter("username"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @MyRequestMapping("/lisi")
    @MySecurity({"lisi"})
    public void lisi(HttpServletRequest request, HttpServletResponse response){
        try {
            response.getWriter().write(request.getParameter("username"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
